package com.example.demo.rabbitmq;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.UUID;

/**
 * @Author: HouZeYu
 * @Description:
 * @Date: Created in 15:38 2019/8/7
 */
@Component
public class SendMessage {
    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void  sendMessage(String message){
        CorrelationData correlationData = new CorrelationData("1234567890"+new Date());
        rabbitTemplate.convertAndSend("zymall.mq.exchange","mq.ceshi", message,correlationData);
    }
    public void send(String msg){
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        System.out.println("发送的消息为"+msg);
        this.rabbitTemplate.convertAndSend("topicExchange","topic",msg,correlationData);
    }

}
